/*******************************************************************************
* @copyright: Shenzhen Hangshun Chip Technology R&D Co., Ltd
* @filename:  hk32g003_it.c
* @brief:     Interrupt Service Routines
* @author:    AE Team
* @version:   V1.0.0/2025-07-16
*             1.Initial version
* @log:
*******************************************************************************/


/* Includes ------------------------------------------------------------------*/
#include "hk32g003_it.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
extern UART_IT_TX_Def Uart1TxBuffer;

/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/******************************************************************************/
/*            Cortex-M0 Processor Exceptions Handlers                         */
/******************************************************************************/

/**
  * @brief  This function handles NMI exception.
  * @param  None
  * @retval None
  */
void NMI_Handler(void)
{
}

/**
  * @brief  This function handles Hard Fault exception.
  * @param  None
  * @retval None
  */
void HardFault_Handler(void)
{
  /* Go to infinite loop when Hard Fault exception occurs */
  while (1)
  {
  }
}

/**
  * @brief  This function handles SVCall exception.
  * @param  None
  * @retval None
  */
void SVC_Handler(void)
{
}

/**
  * @brief  This function handles PendSVC exception.
  * @param  None
  * @retval None
  */
void PendSV_Handler(void)
{
}

/**
  * @brief  This function handles SysTick Handler.
  * @param  None
  * @retval None
  */
void SysTick_Handler(void)
{
}

/******************************************************************************/
/*             HK32G003 Peripherals Interrupt Handlers                   */
/*  Add here the Interrupt Handler for the used peripheral(s) (PPP), for the  */
/*  available peripheral interrupt handler's name please refer to the startup */
/*  file (KEIL_startup_hk32g003.s).                                      */
/******************************************************************************/


/**
  * @brief  This function handles UART1 interrupt request.
  * @param  None
  * @retval None
  */
void UART1_IRQHandler(void)
{
	/* UART1 transfer empty interrupt handle */
	if( UART_GetITStatus(UART1, UART_IT_TXE) != RESET )
	{
		UART_ClearITPendingBit(UART1, UART_IT_TXE);
		
		if( Uart1TxBuffer.Index < Uart1TxBuffer.Len )
		{
			/* Transmit Data */
			UART1->TDR = (Uart1TxBuffer.Data[Uart1TxBuffer.Index] & (uint16_t)0x01FF);
			Uart1TxBuffer.Index ++;
		}
		else
		{
			Uart1TxBuffer.Index = 0;
			Uart1TxBuffer.Len = 0;
			UART_ITConfig(UART1, UART_IT_TXE, DISABLE);  
			UART_ITConfig(UART1, UART_IT_TC, ENABLE);
		}
	}
    
	/* UART1 transfer complete interrupt handle */
	if( UART_GetITStatus(UART1, UART_IT_TC) != RESET )
	{
		UART_ClearITPendingBit(UART1, UART_IT_TC);
		UART_ITConfig(UART1, UART_IT_TC, DISABLE); 
		Uart1TxBuffer.FinishedFlag = SET;
    HK_EVAL_LEDOff(LED1);		
	}
}

/**
  * @}
  */


